package com.bysj.controller;


import com.bysj.entity.Goods;
import com.bysj.entity.News;
import com.bysj.entity.User;
import com.bysj.service.UserService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    UserService userService;
    //存入用户
    @ResponseBody
    @RequestMapping("/insertUser")
    public String insertUser(@RequestBody User user){
          userService.insertUser(user);
          return "success";
    }
    //查询所有用户
    @RequestMapping("/getUserAll")
    @CrossOrigin
    public List<User> getAll(Map map){
        return userService.getAll(map);
    }

    //按openid查询用户
    @RequestMapping("/selectByOpenId")
    public List<User> selectByOpenId(String openid){
        return userService.selectByOpenId(openid);
    }

    //根据id删除用户
    @RequestMapping("/deleteUserById")
    @ResponseBody
    @CrossOrigin
    public String deleteUserById(Integer id){
        userService.deleteUserById(id);
        return "success";
    }

    //更新用户资料
    @RequestMapping("/updataUserInfo")
    @ResponseBody
    public String updateUserInfoById(@RequestBody User user){
        userService.updateUserInfoById(user);
        return "success";
    }
    //分页查询所有用户
    @GetMapping("/getAllUserByPage")
    @CrossOrigin
    public PageInfo<User> getAllUserByPage(Map map,
                                           @RequestParam(defaultValue = "1") int pageNum,
                                           @RequestParam(defaultValue = "10") int pageSize ){
        PageInfo<User> userList = userService.getAllUserByPage(map,pageNum,pageSize);
        return userList;


    }

}
